*** Choose your main folder path here
cd "~\Dropbox\Urban\"
use "Empirical Settings\Persistence of population shocks\Final version.dta", clear
keep if year==1949


****************************************************************************************************************
*** Figure 1
****************************************************************************************************************
preserve
replace popgrowth=round(popgrowth, 0.01)
spmap popgrowth using "Empirical Settings\Persistence of population shocks\gemcoord.dta" if id!=. & us!=., id(id) fcolor(Heat) line(data("Empirical Settings\Persistence of population shocks\newbordhighwcord.dta") size(thick) by(id) color(Black)) clnumber(8)
gr export "Writing\map1.eps", replace
!epstopdf "Writing\map1.eps"
restore


****************************************************************************************************************
*** Table 1: Sumstats
****************************************************************************************************************
sutex spdnat cdunat populationin1 popdensin1 popgrowth us dist sharein1 cathin1 protin1 rel unempl housing alllandin1 turnoutnat if spdnat!=., par nobs dig(2) minmax


****************************************************************************************************************
*** Figure 2: Illustrating identification strategy (see paper)
****************************************************************************************************************


****************************************************************************************************************
*** Figure 3: Motivating graphs
****************************************************************************************************************
preserve
rename (lnpopin1 spdnat cdunat) (lnpop SPD CDU)
lab var SPD "% SPD" 
lab var CDU "% CDU"
lab var lnpop "Ln(pop)"
aaplot SPD lnpop, backdrop(lfitci SPD lnpop, color(gs12)) graphregion(color(white))
gr export "Writing\graph1.eps", replace
!epstopdf "Writing\graph1.eps"

aaplot CDU lnpop, backdrop(lfitci CDU lnpop, color(gs12)) graphregion(color(white))
gr export "Writing\graph3.eps", replace
!epstopdf "Writing\graph3.eps"
restore


****************************************************************************************************************
*** Table 2: Main results
****************************************************************************************************************
*** OLS (Panel A)
eststo drop *
eststo: qui reg spdnat lnpopin1, r
sensemakr spdnat lnpopin1 if dist!=., treat(lnpopin1) 
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r
psacalc delta lnpopin1, rmax(1)
sensemakr spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, treat(lnpopin1) 
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r
psacalc delta lnpopin1, rmax(1)
sensemakr spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1 if dist!=., treat(lnpopin1) 
eststo: qui reg cdunat lnpopin1 if dist!=., r
sensemakr cdunat lnpopin1 if dist!=., treat(lnpopin1) 
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if dist!=., r
psacalc delta lnpopin1, rmax(1)
sensemakr cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if dist!=., treat(lnpopin1)
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1 if dist!=., r
psacalc delta lnpopin1, rmax(1)
sensemakr cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1 if dist!=., treat(lnpopin1) 
esttab using "Table2a.tex", se(3) b(3) replace drop(_cons) ar2 r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat sstat rkf estatp wald_p)


*** IV (Panels B-D)
eststo drop *
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us), r first
weakivtest
estat firststage
estat endogenous
estat overid
weakiv
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
weakivtest
estat firststage
estat endogenous
estat overid
weakiv
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r first
weakivtest
estat firststage
estat endogenous
estat overid
weakiv

eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us), r first
weakivtest
estat firststage
estat endogenous
estat overid
weakiv
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
weakivtest
estat firststage
estat endogenous
estat overid
weakiv
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r first
weakivtest
estat firststage
estat endogenous
estat overid
weakiv
esttab using "Table2b.tex", se(3) b(3) replace drop(_cons) ar2 r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat sstat rkf estatp wald_p)


****************************************************************************************************************
*** Figure 4: Visualizing results
****************************************************************************************************************
preserve
qui reg difference lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if dist!=., r
global coef1=_b[lnpopin1]
global se1=_se[lnpopin1]
global obs1 =e(N)
global t1=invttail($obs1, 0.05)
global linter1= $coef1 - ( $t1 * $se1)
global uinter1= $coef1 + ( $t1 * $se1)
g coef1=0.1*$coef1
g linter1=0.1*$linter1
g uinter1=0.1*$uinter1

qui ivregress 2sls difference (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r
global coef2=_b[lnpopin1]
global se2=_se[lnpopin1]
global obs2 =e(N)
global t2=invttail($obs2, 0.05)
global linter2= $coef2 - ( $t2 * $se2)
global uinter2= $coef2 + ( $t2 * $se2)
g coef2=0.1*$coef2
g linter2=0.1*$linter2
g uinter2=0.1*$uinter2

global coef3=_b[sharein1]
global se3=_se[sharein1]
global obs3 =e(N)
global t3=invttail( $obs3, 0.05)
global linter3= $coef3 - ( $t3 * $se3)
global uinter3= $coef3 + ( $t3 * $se3)
g coef3=5.352595*$coef3
g linter3=5.352595*$linter3
g uinter3=5.352595*$uinter3

global coef4=_b[rel]
global se4=_se[rel]
global obs4 =e(N)
global t4=invttail( $obs4, 0.05)
global linter4= $coef4 - ( $t4 * $se4)
global uinter4= $coef4 + ( $t4 * $se4)
g coef4=1.321573*$coef4
g linter4=1.321573*$linter4
g uinter4=1.321573*$uinter4

global coef5=_b[unempl]
global se5=_se[unempl]
global obs5 =e(N)
global t5=invttail( $obs5, 0.05)
global linter5= $coef5 - ( $t5 * $se5)
global uinter5= $coef5 + ( $t5 * $se5)
g coef5=1.329233*$coef5
g linter5=1.329233*$linter5
g uinter5=1.329233*$uinter5

global coef6=_b[housing]
global se6=_se[housing]
global obs6 =e(N)
global t6=invttail( $obs6, 0.05)
global linter6= $coef6 - ( $t6 * $se6)
global uinter6= $coef6 + ( $t6 * $se6)
g coef6=0.02259683*$coef6
g linter6=0.02259683*$linter6
g uinter6=0.02259683*$uinter6

global coef7=_b[alllandin1]
global se7=_se[alllandin1]
global obs7 =e(N)
global t7=invttail( $obs7, 0.05)
global linter7= $coef7 - ( $t7 * $se7)
global uinter7= $coef7 + ( $t7 * $se7)
g coef7=99.85692*$coef7
g linter7=99.85692*$linter7
g uinter7=99.85692*$uinter7

global coef8=_b[turnoutnat]
global se8=_se[turnoutnat]
global obs8 =e(N)
global t8=invttail( $obs8, 0.05)
global linter8= $coef8 - ( $t8 * $se8)
global uinter8= $coef8 + ( $t8 * $se8)
g coef8=6.573544*$coef8
g linter8=6.573544*$linter8
g uinter8=6.573544*$uinter8

gen id1=_n
reshape long coef linter uinter, i(id1) j(reg)

collapse (mean) coef* lint* uint* , by(reg)
lab var coef "Coefficient"
lab var linter "Confidence"
lab var uinter "interval"

graph twoway (scatter coef reg, msize(large) msymbol(diamond_hollow) lcolor(gs2) fcolor(gs10) yline(0, extend lpattern(vthick))) (rcap linter uinter reg, lwidth(thick) lcolor(gs2) fcolor(gs10)), legend(off) ytitle("Implied change in SPD - CDU") xtitle("") xlabel(1 "pop size (OLS)" 2 "pop size (IV)" 3 "% females" 4 "Protestant / Catholic" 5 "% unemployed" 6 "Apartments/capita" 7 "Land size" 8 "% turnout", angle(forty_five)) yscale(range(-8 8)) ylabel(-8(4)8) xscale(range(0.5 8.5)) title("") graphregion(color(white)) 
gr export "Writing\final.eps", replace
!epstopdf "Writing\final.eps"
restore


****************************************************************************************************************
****************************************************************************************************************
*** Supplementary material
****************************************************************************************************************
****************************************************************************************************************

****************************************************************************************************************
*** Figure A1: Campaign posters
****************************************************************************************************************


****************************************************************************************************************
*** Table B1: Variable means by French and US side
****************************************************************************************************************
preserve 
replace dist=-dist if us==1
ttest dist, by(us)
restore 

foreach x of varlist spdnat cdunat populationin1 popdensin1 popgrowth sharein1 cathin1 protin1 rel unempl housing alllandin1 turnoutnat {
	ttest `x', by(us)
}


****************************************************************************************************************
*** Table B2: Summary statistics of additional variables
****************************************************************************************************************
sutex fdpnat shareexp highway capital spdland cduland, par nobs dig(2) minmax

sutex spd1932 agric hhpc singleshare rtaxin1 if spd1932!=. & agric!=. & hhpc!=. & singleshare!=. & rtaxin1!=., par nobs dig(2) minmax



****************************************************************************************************************
*** Table B3: Main results, displaying all covariates -- see Table 2 above
****************************************************************************************************************


****************************************************************************************************************
*** Table B4: Robustness checks
****************************************************************************************************************
*** OLS SPD
eststo drop *
* Only close to border
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if dist>-10 & dist<10, r 
* Remove 2 biggest counties 
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if countyold!="Calw" & county!="Biberach", r 
* Binary instrument 
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r
* Only linear IVs
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r 
* All BW
preserve
use "Empirical Settings\Persistence of population shocks\Final version full BW.dta", clear
egen allus=rowmax(us usother)
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r 
restore
* Popdens
eststo: qui reg spdnat popdensin1 sharein1 rel unempl alllandin1 housing turnoutnat, r 
* Pop growth
eststo: qui reg spdnat popgrowth sharein1 rel unempl alllandin1 housing turnoutnat, r 
* Predicting CDU+FDP voting: Only available for Panel B below
* DiD in 1st stage, incl. 1932 election
preserve 
use "Empirical Settings\Persistence of population shocks\Final version.dta", clear
sort countyold mun year
by countyold mun: replace rel=rel[_n+1] if year==1932
g spdvote=spd1932 if year==1932
replace spdvote=spdnat if year==1949
g after=(year==1949)
g afterus=after*us
g afterdist=after*dist
g afterdistus=after*distus
eststo: reg spdvote lnpopin1 after us dist sharein1 rel alllandin1, r first
restore
* Adding distances to motorway and Stuttgart
eststo: qui reg spdnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat highway highway2 capital capital2, r
esttab using "TableB4aOLS.tex", se(3) b(3) replace drop(_cons sharein1 rel unempl alllandin1 housing turnoutnat) ar2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat) 


*** IV SPD
eststo drop *
* Only close to border
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat if dist>-10 & dist<10, r first
estat firststage
* Remove 2 biggest counties
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat if countyold!="Calw" & county!="Biberach", r first
estat firststage 
* Binary instrument
eststo: qui ivregress 2sls spdnat (lnpopin1=us) sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage
* Only linear IVs
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage 
* All BW
preserve
use "Empirical Settings\Persistence of population shocks\Final version full BW.dta", clear
egen allus=rowmax(us usother)
eststo: qui ivregress 2sls spdnat (lnpopin1=allus) sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage
restore
* Popdens
eststo: qui ivregress 2sls spdnat (popdensin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
estat firststage
* Pop growth
eststo: qui ivregress 2sls spdnat (popgrowth=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
estat firststage
* Predicting CDU+FDP voting: Only available for Panel B below
* DiD in 1st stage, incl. 1932 election
preserve 
use "Empirical Settings\Persistence of population shocks\Final version.dta", clear
sort countyold mun year
by countyold mun: replace rel=rel[_n+1] if year==1932
keep if year==1932 | year==1949
g spdvote=spd1932 if year==1932
replace spdvote=spdnat if year==1949
g after=(year==1949)
g afterus=after*us
g afterdist=after*dist
g afterdistus=after*distus
eststo: ivregress 2sls spdvote (lnpopin1=afterus afterdist afterdistus) after us dist sharein1 rel alllandin1 if sample==1, r first
estat firststage
restore
* Adding distances to motorway and Stuttgart
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat highway highway2 capital capital2 if year==1949, r first
estat firststage
esttab using "TableB4aIV.tex", se(3) b(3) replace drop(_cons sharein1 rel unempl alllandin1 housing turnoutnat) r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat)


*** OLS CDU
eststo drop *
* Only close to border
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if dist>-10 & dist<10, r 
* Remove 2 biggest counties 
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if countyold!="Calw" & county!="Biberach", r 
* Binary instrument 
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r
* Only linear IVs
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r 
* All BW
preserve
use "Empirical Settings\Persistence of population shocks\Final version full BW.dta", clear
egen allus=rowmax(us usother)
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r 
restore
* Popdens
eststo: qui reg cdunat popdensin1 sharein1 rel unempl alllandin1 housing turnoutnat, r 
* Pop growth
eststo: qui reg cdunat popgrowth sharein1 rel unempl alllandin1 housing turnoutnat, r 
* Predicting cdunat+fdpnat
eststo: qui reg right lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r first
* Adding distances to motorway and Stuttgart
eststo: qui reg cdunat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1 highway highway2 capital capital2, r
esttab using "TableB4bOLS.tex", se(3) b(3) replace drop(_cons sharein1 rel unempl alllandin1 housing turnoutnat) ar2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat) 


*** IV CDU
eststo drop *
* Only close to border
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat if dist>-10 & dist<10, r first
estat firststage
* Remove 2 biggest counties
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat if countyold!="Calw" & county!="Biberach", r first
estat firststage
* Binary instrument
eststo: qui ivregress 2sls cdunat (lnpopin1=us) sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage 
* Only linear IVs
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage 
* All BW
preserve
use "Empirical Settings\Persistence of population shocks\Final version full BW.dta", clear
egen allus=rowmax(us usother)
eststo: qui ivregress 2sls cdunat (lnpopin1=allus) sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage
restore
* Popdens
eststo: qui ivregress 2sls cdunat (popdensin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
estat firststage
* Pop growth
eststo: qui ivregress 2sls cdunat (popgrowth=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
estat firststage
* Predicting cdunat+fdpnat
eststo: qui ivregress 2sls right (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage
* Adding distances to motorway and Stuttgart
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat highway highway2 capital capital2 if year==1949, r first
estat firststage 
esttab using "TableB4bIV.tex", se(3) b(3) replace drop(_cons sharein1 rel unempl alllandin1 housing turnoutnat) r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat)



****************************************************************************************************************
*** Table B5: Main results when controlling for expellee share
****************************************************************************************************************
eststo drop *
eststo: qui reg spdnat lnpopin1 shareexp, r
eststo: qui reg spdnat lnpopin1 shareexp sharein1 rel unempl alllandin1 housing turnoutnat, r
eststo: qui reg spdnat lnpopin1 shareexp sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r
eststo: qui reg cdunat lnpopin1 shareexp, r
eststo: qui reg cdunat lnpopin1 shareexp sharein1 rel unempl alllandin1 housing turnoutnat if dist!=., r
eststo: qui reg cdunat lnpopin1 shareexp sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1 if dist!=., r
esttab using "TableB5a.tex", se(3) b(3) replace r2 star(* 0.10 ** 0.05 *** 0.01) drop(_cons sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1) sca(fstat)


eststo drop *
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) shareexp if year==1949, r first
estat firststage
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) shareexp sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage
eststo: qui ivregress 2sls spdnat (lnpopin1=us dist dist2 distus dist2us) shareexp sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1 if year==1949, r first
estat firststage
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) shareexp if year==1949, r first
estat firststage
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) shareexp sharein1 rel unempl alllandin1 housing turnoutnat if year==1949, r first
estat firststage
eststo: qui ivregress 2sls cdunat (lnpopin1=us dist dist2 distus dist2us) shareexp sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1 if year==1949, r first
estat firststage
esttab using "TableB5b.tex", se(3) b(3) replace r2 star(* 0.10 ** 0.05 *** 0.01) drop(_cons sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1) sca(fstat)


****************************************************************************************************************
*** Table B6: Sumstats for all BW
****************************************************************************************************************
preserve
use "Empirical Settings\Persistence of population shocks\Final version full BW.dta", clear

egen allus=rowmax(us usother)
sutex spdnat cdunat populationin1 turnoutnat sharein1 rel unempl housing alllandin1 if cdunat!=. & protin1!=. & cathin1!=. & unempl!=., par nobs dig(2) minmax
restore


****************************************************************************************************************
*** Table B7: Partial effects from fractional response regressions
****************************************************************************************************************
*** Please see attached R files "R code fractional response regressions" and "R code session info". 


****************************************************************************************************************
*** Table B8: Landtags elections in 1952 (use persistence of pop shocks paper as motivation why ppl stayed)
****************************************************************************************************************
*** OLS
eststo drop *
eststo: qui reg spdland lnpopin1, r
sensemakr spdland lnpopin1, treat(lnpopin1) 
eststo: qui reg spdland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r
psacalc delta lnpopin1, rmax(1)
sensemakr spdland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, treat(lnpopin1) 
eststo: qui reg spdland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r
psacalc delta lnpopin1, rmax(1)
sensemakr spdland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, treat(lnpopin1) 
eststo: qui reg cduland lnpopin1, r
sensemakr cduland lnpopin1, treat(lnpopin1) 
eststo: qui reg cduland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r
psacalc delta lnpopin1, rmax(1)
sensemakr cduland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, treat(lnpopin1)
 eststo: qui reg cduland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r
psacalc delta lnpopin1, rmax(1)
sensemakr cduland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, treat(lnpopin1) 
esttab using "TableB8a.tex", se(3) b(3) replace drop(_cons) ar2 r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat sstat rkf estatp wald_p)


*** IV
eststo drop *
eststo: qui ivregress 2sls spdland (lnpopin1=us dist dist2 distus dist2us), r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls spdland (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls spdland (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls cduland (lnpopin1=us dist dist2 distus dist2us), r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls cduland (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls cduland (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r first
weakivtest
estat firststage
estat endogenous
weakiv
esttab using "TableB8b.tex", se(3) b(3) replace drop(_cons) ar2 r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat sstat rkf estatp wald_p)


****************************************************************************************************************
*** Table B9: FDP results
****************************************************************************************************************
*** OLS
eststo drop *
eststo: qui reg fdpnat lnpopin1, r
sensemakr fdpnat lnpopin1, treat(lnpopin1) 
eststo: qui reg fdpnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r
psacalc delta lnpopin1, rmax(1)
sensemakr fdpnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, treat(lnpopin1) 
eststo: qui reg fdpnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r
psacalc delta lnpopin1, rmax(1)
sensemakr fdpnat lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, treat(lnpopin1) 
eststo: qui reg fdpland lnpopin1, r
sensemakr fdpland lnpopin1, treat(lnpopin1) 
eststo: qui reg fdpland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, r
psacalc delta lnpopin1, rmax(1)
sensemakr fdpland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat, treat(lnpopin1)
eststo: qui reg fdpland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r
psacalc delta lnpopin1, rmax(1)
sensemakr fdpland lnpopin1 sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, treat(lnpopin1) 
esttab using "TableB9a.tex", se(3) b(3) replace drop(_cons) ar2 r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat sstat rkf estatp wald_p)


*** IV
eststo drop *
eststo: qui ivregress 2sls fdpnat (lnpopin1=us dist dist2 distus dist2us), r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls fdpnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls fdpnat (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls fdpland (lnpopin1=us dist dist2 distus dist2us), r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls fdpland (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat, r first
weakivtest
estat firststage
estat endogenous
weakiv
eststo: qui ivregress 2sls fdpland (lnpopin1=us dist dist2 distus dist2us) sharein1 rel unempl alllandin1 housing turnoutnat spd1932 agric hhpc singleshare rtaxin1, r first
weakivtest
estat firststage
estat endogenous
weakiv
esttab using "TableB9b.tex", se(3) b(3) replace drop(_cons) ar2 r2 star(* 0.10 ** 0.05 *** 0.01) sca(fstat sstat rkf estatp wald_p)


****************************************************************************************************************
*** Calculate compositional example
****************************************************************************************************************
* Solve equation (13) for s^{N,SPD}
g snspd=spdnat-(noexpellees/(populationin1-noexpellees))*12.013
* Use result to solve equation (12) for x^{SPD}
g xspd=((spdnat/snspd)-(1-shareexp))/shareexp
* Generate s^{E,SPD}
g sespd=snspd*xspd

* Same for CDU
g sncdu=cdunat+(noexpellees/(populationin1-noexpellees))*38.478
g xcdu=((cdunat/sncdu)-(1-shareexp))/shareexp
g secdu=sncdu*xcdu
